package cn.iocoder.yudao.module.contract.dal.mysql.contractTemplate;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.contract.dal.dataobject.contractTemplate.ContractTemplateDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.contract.controller.admin.contractTemplate.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 合同模板 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ContractTemplateMapper extends BaseMapperX<ContractTemplateDO> {

    default PageResult<ContractTemplateDO> selectPage(ContractTemplatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContractTemplateDO>()
                .likeIfPresent(ContractTemplateDO::getContractTypeName, reqVO.getContractTypeName())
                .likeIfPresent(ContractTemplateDO::getContractName, reqVO.getContractName())
                .likeIfPresent(ContractTemplateDO::getClientName, reqVO.getClientName())
                .eqIfPresent(ContractTemplateDO::getContractCode, reqVO.getContractCode())
                .betweenIfPresent(ContractTemplateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ContractTemplateDO::getCreateTime));
    }

    @Select("SELECT count(1)  FROM ct_framework_agreement  WHERE YEAR ( agreement_start_date ) = YEAR ( #{agreementStartDate} );")
    long countByYear(String agreementStartDate);
}